﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Profile;
using System.Data;

namespace WebSite.admin.product
{
    public partial class goods_batch_select_add02 : System.Web.UI.Page
    {


        // Methods
        private void Bind()
        {
            this.Labelname.Text = "<table width='98%' border='0' cellpadding='0' cellspacing='1'><tr bgcolor='#E2E7EB'><td align='left' class='title01' height='25'>商品名称</td></tr>";
            string sql = "Select * From DB_Shoppro where proid in (" + base.Request.QueryString["pid"].ToString() + ")";
            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count > 0)
            {
                this.Labelname.Text = this.Labelname.Text + "<tr><td>";
                foreach (DataRow row in table.Rows)
                {
                    this.Labelname.Text = this.Labelname.Text + row["proname"].ToString() + ",";
                }
                this.Labelname.Text = this.Labelname.Text + "</td></tr>";
            }
            this.Labelname.Text = this.Labelname.Text + "</table>";
            this.Labelcontent.Text = "<table width='98%' border='0' cellpadding='0' cellspacing='1'><tr bgcolor='#E2E7EB'><td align='left' class='title01'>市场价格</td><td align='left' class='title01'>本店价格</td>";
            sql = "Select * From DB_memberank";
            DataTable table2 = new DataTable();
            table2 = SQLAccess.GreatDs(sql).Tables[0];
            if (table2.Rows.Count > 0)
            {
                foreach (DataRow row2 in table2.Rows)
                {
                    this.Labelcontent.Text = this.Labelcontent.Text + "<td align='left' class='title01'>" + row2["rank"].ToString() + "</td>";
                }
            }
            this.Labelcontent.Text = this.Labelcontent.Text + "<td align='left' class='title01'>积分购买</td><td align='left' class='title01'>赠送积分</td><td align='left' class='title01'>库存</td><td align='left' class='title01'>品牌</td></tr>";
            if (base.Request.QueryString["pid"] != null)
            {
                this.Labelcontent.Text = this.Labelcontent.Text + "<td><input id='proprice3' name='proprice3' runat='server' size='2' /></td>";
                this.Labelcontent.Text = this.Labelcontent.Text + "<td><input id='proprice1' name='proprice1' runat='server' size='2' /></td>";
                sql = "Select * From DB_memberank";
                DataTable table3 = new DataTable();
                table3 = SQLAccess.GreatDs(sql).Tables[0];
                if (table3.Rows.Count > 0)
                {
                    foreach (DataRow row3 in table3.Rows)
                    {
                        string text = this.Labelcontent.Text;
                        this.Labelcontent.Text = text + "<td><input id='proprice2_" + row3["rankid"].ToString() + "' name='proprice2_" + row3["rankid"].ToString() + "' runat='server' size='2' value='0' /></td>";
                    }
                }
                this.Labelcontent.Text = this.Labelcontent.Text + "<td><input id='proscore2' name='proscore2' runat='server' size='2' /></td>";
                this.Labelcontent.Text = this.Labelcontent.Text + "<td><input id='proscore1' name='proscore1' runat='server' size='2' /></td>";
                this.Labelcontent.Text = this.Labelcontent.Text + "<td><input id='proku1' name='proku1' runat='server' size='2' /></td>";
                this.Labelcontent.Text = this.Labelcontent.Text + "<td><select name='propinpai' id='propinpai' runat='server'><option value='0'>请选择</option>";
                sql = "Select * From DB_pinpai where visible=1";
                DataTable table4 = new DataTable();
                table4 = SQLAccess.GreatDs(sql).Tables[0];
                if (table4.Rows.Count > 0)
                {
                    foreach (DataRow row4 in table4.Rows)
                    {
                        string str3 = this.Labelcontent.Text;
                        this.Labelcontent.Text = str3 + "<option value='" + row4["pinpaiid"].ToString() + "'>" + row4["pinpainame"].ToString() + "</option>";
                    }
                }
                this.Labelcontent.Text = this.Labelcontent.Text + "</select></td></tr>";
            }
            this.Labelcontent.Text = this.Labelcontent.Text + "</table>";
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            if (base.Request.QueryString["pid"] != null)
            {
                string[] strArray = base.Request.QueryString["pid"].ToString().Split(new char[] { ',' });
                for (int i = 0; i < strArray.Length; i++)
                {
                    if ((strArray[i].ToString() != "0") && (strArray[i].ToString() != ""))
                    {
                        SQLAccess.DoSql("update DB_Shoppro set proprice3=" + base.Request.Form["proprice3"] + ",proprice1=" + base.Request.Form["proprice1"] + ",proscore1=" + base.Request.Form["proscore1"] + ",proscore2=" + base.Request.Form["proscore2"] + ",proku1=" + base.Request.Form["proku1"] + ",propinpai=" + base.Request.Form["propinpai"] + " where proid=" + strArray[i] + "");
                        string sql = "Select * From DB_memberprice where productid=" + strArray[i] + "";
                        DataTable table = new DataTable();
                        table = SQLAccess.GreatDs(sql).Tables[0];
                        if (table.Rows.Count > 0)
                        {
                            foreach (DataRow row in table.Rows)
                            {
                                SQLAccess.DoSql("update DB_memberprice set [price]=" + base.Request.Form["proprice2_" + row["rankid"].ToString()] + " where rankid=" + row["rankid"].ToString() + " and productid=" + strArray[i] + "");
                            }
                        }
                    }
                }
                base.Response.Write("<script language='javascript'>alert('更新成功！');window.location.href='goods_batch_select.aspx';</script>");
                base.Response.End();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.Session["Adminlogin"] == null)
            {
                base.Response.Write("<script language=javascript>window.top.location.href='../login.aspx';</script>");
                base.Response.End();
            }
            this.ImageButton2.Attributes["onclick"] = "return clicks()";
            if (!base.IsPostBack)
            {
                this.Bind();
            }
        }

 

    }
}